#include<iostream>
#include<sqlite3.h>

class SqilteHelper{
    public:
        typedef int(*SqliteCallback)(void*,int,char**,char**);
        SqilteHelper(const std::string& dbpath):_db_filepath(dbpath),_hander(nullptr){
        }
        bool open(){
            int ret = sqlite3_open_v2(_db_filepath.c_str(),&_hander,SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE
             | SQLITE_OPEN_FULLMUTEX,nullptr);
             if(ret != SQLITE_OK){
                std::cout<<"sqlite open false..."<<std::endl;
                std::cout<<sqlite3_errmsg(_hander)<<std::endl;
                return false;
             }
             return true;
        }
        bool exec(const std::string& sql,SqliteCallback cb,void* arg){
            //sqlite3_exec(sqlite3*, char *sql, int (*callback)(void*, int, char**, char**),void* arg, char **err)
            int ret = sqlite3_exec(_hander,sql.c_str(),cb,arg,nullptr);
            if(ret != SQLITE_OK){
                std::cout<<"sqlite exec false..."<<std::endl;
                std::cout<<sqlite3_errmsg(_hander)<<std::endl;
                return false;
            }
            return true;
        }
        bool close(){
            int ret = sqlite3_close_v2(_hander);
            if(ret != SQLITE_OK){
                std::cout<<"sqlite close false..."<<std::endl;
                std::cout<<sqlite3_errmsg(_hander)<<std::endl;
                return false;
            }
            return true; 
        }
    private:
        sqlite3* _hander;
        std::string _db_filepath;
};